import config from './config'
let func = {
	navigateTo(e) {
		uni.navigateTo({
			url: e.currentTarget.dataset.url
		})
	},
	toUrl(url) {
		uni.navigateTo({
			url: url
		})
	},
	redirectTo(e) {
		uni.navigateTo({
			url: e.currentTarget.dataset.url
		})
	},
	webUrl(url = '') {
		return config.website + url
	},
	webAppUrl(url = '') {
		return config.website + '/statics/images/app/' + url
	},
	ossUrl(url = '') {
		// return 'background-image: url(' + config.ossUrl + url + ');'
		return config.ossUrl + url
	},
	bg(url = '') {
		const path = url.indexOf('http')>-1?'':config.ossUrl
		return {
			backgroundImage: 'url(' + path + url + ')'
		}
	},
	website(url = '') {
		return 'http://ylhl.oshainiu.cn' + url
	},
	checkPhone(phone) {
		if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone))) {
			return false;
		} else {
			return true
		}
	},
	checkTelephone(phone) {
		return /^((\+86)|(86))?(1)\d{10}$/.test(phone) || /^0[0-9-]{10,13}$/.test(phone);
	},
	getThumb(img) {
		let arr = []
		if (img) {
			arr = img.split(',')

		}
		if (arr.length > 0) {
			return arr[0]
		} else {
			return ""
		}
	},
	getSystemInfo() {
		return new Promise((resolve, reject) => {
			uni.getSystemInfo({
				success: function(res) {
					resolve(res);
					// console.log(res.model);
					// console.log(res.pixelRatio);
					// console.log(res.windowWidth);
					// console.log(res.windowHeight);
					// console.log(res.language);
					// console.log(res.version);
					// console.log(res.platform);
				},
				fail(err) {
					resolve(err);
				}
			});

		});
	},
	getWords(e, len = 32) { // js字数与数据库字符数不一样
		let b = 0 // 输入的字符数
		let newArr = []
		let newStr = ""
		for (var i = 0, length = e.length; i < length; i++) {
			var c = e.charAt(i);
			if (/^[\u0000-\u00ff]$/.test(c)) {
				b++;
			} else { b += 2; }

			if (b <= len) {

			} else {
				newArr.push(newStr)
				b = 0
				newStr = ""
			}
			newStr = newStr + e.charAt(i)

		}
		newArr.push(newStr)
		return newArr
	},
	curRoute() {
		let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
		let curRoute = routes[routes.length - 1].route //获取当前页面路由
		return curRoute
	},
}

export default func